//
//  RunDtaeRecordCell.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/2/22.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "RunDtaeRecordCell.h"

#import "ZFChart.h"


@interface RunDtaeRecordCell ()<ZFGenericChartDataSource, ZFBarChartDelegate>

@property (nonatomic,strong) ZFBarChart * barChart;
@end



@implementation RunDtaeRecordCell
{
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.backgroundColor = kWhiteColor;
        
        UILabel * lefTitL = [ReduceCode creatLabelWithFrame:CGRectMake(10, 20, 80, 14) title:@"训练记录" titleColor:UIColorFromRGB(0x333333) font:16 textAlignment:NSTextAlignmentLeft];
        lefTitL.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        [self.contentView addSubview:lefTitL];
        
        
        UILabel * weekTimerL = [ReduceCode creatLabelWithFrame:CGRectMake(10, kMaxY(lefTitL.frame)+8,kScreenWidth-40, 11) title:@"本周累计训练20分钟" titleColor:UIColorFromRGB(0x666666) font:11 textAlignment:NSTextAlignmentLeft];
//        weekTimerL.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        [self.contentView addSubview:weekTimerL];
        

        UIButton * rigBtn = [UIButton creatBtnWithFrame:CGRectMake(kScreenWidth-100, 0, 100, 30) btnTitle:@"全部记录" btnTitleColor:UIColorFromRGB(0x333333) btnTitleFont:16 btnTagPrice:0 btnSetImage:IMAGE(@"point") btnBackgroundColor:nil isCorner:NO action:^(UIButton *button) {
            
            
        }];
        rigBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        [rigBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        rigBtn.centerY = lefTitL.centerY;
        
        [self.contentView addSubview:rigBtn];

        
        self.barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(0, kMaxY(weekTimerL.frame), SCREEN_WIDTH, 145)];
        _barChart.dataSource = self;
        _barChart.delegate = self;
        _barChart.isAnimated = YES;
        _barChart.xAxisColor = kClearColor;
        _barChart.yAxisColor = kClearColor;
        _barChart.isShowAxisArrows = NO;
        _barChart.axisLineValueColor = kClearColor;
        _barChart.axisLineNameColor = UIColorFromRGB(0x666666);
        _barChart.isShowAxisLineValue = NO;

        [self.contentView addSubview:self.barChart];
        
        [self.barChart strokePath];

        
        
        
        
        
        
    }
    
    return self;
}

//pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
    return @[@"12", @"67", @"80", @"28", @"100", @"23",@"5"];
}

- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
    return @[@"01/09", @"10", @"11", @"12", @"13", @"14",@"15"];
}

- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    return @[ZFMagenta];
}


#pragma mark - ZFBarChartDelegate

- (CGFloat)barWidthInBarChart:(ZFBarChart *)barChart{
    return 15.f;
}

- (CGFloat)paddingForGroupsInBarChart:(ZFBarChart *)barChart{
    
    return (kScreenWidth-15*6)/8;
}

//- (id)valueTextColorArrayInBarChart:(ZFGenericChart *)barChart{
//    return ZFBlue;
//}

- (NSArray *)gradientColorArrayInBarChart:(ZFBarChart *)barChart{
    
    ZFGradientAttribute * gradientAttribute = [[ZFGradientAttribute alloc] init];
    gradientAttribute.colors = @[(id)kLineColor.CGColor, (id)ZFWhite.CGColor];
    gradientAttribute.locations = @[@(0.5), @(1)];
    
    return [NSArray arrayWithObjects:gradientAttribute, nil];
}

//- (void)barChart:(ZFBarChart *)barChart didSelectBarAtGroupIndex:(NSInteger)groupIndex barIndex:(NSInteger)barIndex bar:(ZFBar *)bar popoverLabel:(ZFPopoverLabel *)popoverLabel{
//    NSLog(@"第%ld组========第%ld个",(long)groupIndex,(long)barIndex);
//    
//    //可在此处进行bar被点击后的自身部分属性设置,可修改的属性查看ZFBar.h
////    bar.barColor = ZFGold;
////    bar.isAnimated = YES;
////    //    bar.opacity = 0.5;
////    [bar strokePath];
//    
//    //可将isShowAxisLineValue设置为NO，然后执行下句代码进行点击才显示数值
//    //    popoverLabel.hidden = NO;
//}
//
//- (void)barChart:(ZFBarChart *)barChart didSelectPopoverLabelAtGroupIndex:(NSInteger)groupIndex labelIndex:(NSInteger)labelIndex popoverLabel:(ZFPopoverLabel *)popoverLabel{
//    NSLog(@"第%ld组========第%ld个",(long)groupIndex,(long)labelIndex);
//    
//    //可在此处进行popoverLabel被点击后的自身部分属性设置
//    //    popoverLabel.textColor = ZFSkyBlue;
//    //    [popoverLabel strokePath];
//}



+(NSString *)cellReuseID:(NSInteger)section {
    
    if (section == 0) {
        return @"RunDateMostCell";
    }else if (section == 1) {
        return @"RunDateBeforeCell";
    }else{
        return @"RunDtaeRecordCell";
    }
 
}
+(CGFloat)cellForHeight:(NSInteger)section {
    
    if (section == 0) {
        return 65+92;
    }else if (section == 1) {
        return 134;
    }else{
        return 200;
    }
  
    
}

@end
